<?php
/**
 * Model dla klasy User
 *
 * @author ModGen
 */

class User extends DataObject{


	/**
	 * nazwa tabeli
	 */
	static $tableName = 'user';

	/**
	 * nazwa klucza tabeli
	 */
	static $classTablePK = 'id_user';

	/**
	 * nazwa klasy
	 */
	static $className = __CLASS__;
	
	static $password_hash = '4raFR2St7xeTraSpEsPaQacr4xePr6R4';
	

	/**
	 * tablica mapująca pola klasy
	 */
	static $fields = array(
		'id_user' => 'id',
		'status' => 'status',
		'date_insert' => 'dateInsert',
		'date_update' => 'dateUpdate',
		'user_type' => 'userType',
		'active' => 'active',
		'online' => 'online',
		'points' => 'points',
		'gender' => 'gender',
		'advertisement' => 'advertisement',
		'values_metric' => 'valuesMetric',
		'price_compare' => 'priceCompare',
		'looking_for_partner' => 'lookingForPartner',
		'weight' => 'weight',
		'height' => 'height',
		'last_login' => 'lastLogin',
		'email' => 'email',
		'new_email' => 'newEmail',
		'password' => 'password',
		'hash' => 'hash',
		'location' => 'location',
		'language' => 'language',
		'description' => 'description',
		'avatar' => 'avatar',
		'first_name'=>'firstName',
		'last_name'=>'lastName',
		'state' => 'state',
		'city' => 'city',
		'birth_date' => 'birthDate',
		'badge_cache' => 'badgeCache',
		'is_expert' => 'isExpert',
		'is_vip' => 'isVip',
		'premium' => 'premium',
	);


	protected $id;
	private $status;
	private $dateInsert;
	private $dateUpdate;
	private $userType;
	private $active;
	private $online;
	private $points;
	private $gender;
	private $advertisement;
	private $valuesMetric;
	private $priceCompare;
	private $lookingForPartner;
	private $weight;
	private $height;
	private $lastLogin;
	private $email;
	private $newEmail;
	private $password;
	private $hash;
	private $location;
	private $language;
	private $description;
	private $avatar;
	private $firstName;
	private $lastName;
	private $state;
	private $city;
	private $birthDate;
	private $badgeCache;
	private $isExpert;
	private $isVip;
	private $premium;


	public $commentsCount;
	public $productCommentsCount;
	public $connectionsCount;
	public $userExtendedProfile;
	public $userProfilePermission;



	// -- Konstruktor --


	function __construct( $id = -1 , $status = null, $dateInsert = null, $dateUpdate = null, $userType = null, $active = null, $online = null, $points = null, $gender = null, $advertisement = null, $valuesMetric = null, $priceCompare = null, $lookingForPartner = null, $weight = null, $height = null, $lastLogin = null, $email = null, $newEmail = null, $password = null, $hash = null, $location = null, $language = null, $description = null, $avatar = null){
		$this->id = $id;
		$this->status = $status;
		$this->dateInsert = $dateInsert;
		$this->dateUpdate = $dateUpdate;
		$this->userType = $userType;
		$this->active = $active;
		$this->online = $online;
		$this->points = $points;
		$this->gender = $gender;
		$this->advertisement = $advertisement;
		$this->valuesMetric = $valuesMetric;
		$this->priceCompare = $priceCompare;
		$this->lookingForPartner = $lookingForPartner;
		$this->weight = $weight;
		$this->height = $height;
		$this->lastLogin = $lastLogin;
		$this->email = $email;
		$this->newEmail = $newEmail;
		$this->password = $password;
		$this->hash = $hash;
		$this->location = $location;
		$this->language = $language;
		$this->description = $description;
		$this->avatar = $avatar;
	}

	public function getPremium()
	{
		return $this->premium;
	}
	
	public function setPremium($val)
	{
		$this->premium = $val;
	}
	

	public function getCommentsCount() {
		return $this->commentsCount;
	}

	public function setCommentsCount($commentsCount) {
		$this->commentsCount = $commentsCount;
	}

	public function getProductCommentsCount() {
		return $this->productCommentsCount;
	}

	public function setProductCommentsCount($productCommentsCount) {
		$this->productCommentsCount = $productCommentsCount;
	}

	public function getConnectionsCount() {
		return $this->connectionsCount;
	}

	public function setConnectionsCount($connectionsCount) {
		$this->connectionsCount = $connectionsCount;
	}

			
	// -- Get-y i Set-y --

	public function getId(){
		return $this->id;
	}

	public function setId($id){
		$this->id = $id;
	}

	public function getFirstName() {
		return $this->firstName;
	}

	public function setFirstName($firstName) {
		$this->firstName = $firstName;
	}

	public function getLastName() {
		return $this->lastName;
	}

	public function setLastName($lastName) {
		$this->lastName = $lastName;
	}

		
	public function getStatus(){
		return $this->status;
	}

	public function setStatus($status){
		$this->status = $status;
	}

	
	public function getDateInsert(){
		return $this->dateInsert;
	}

	public function setDateInsert($dateInsert){
		$this->dateInsert = $dateInsert;
	}

	
	public function getDateUpdate(){
		return $this->dateUpdate;
	}

	public function setDateUpdate($dateUpdate){
		$this->dateUpdate = $dateUpdate;
	}

	
	public function getUserType(){
		return $this->userType;
	}

	public function setUserType($userType){
		$this->userType = $userType;
	}

	
	public function getActive(){
		return $this->active;
	}

	public function setActive($active){
		$this->active = $active;
	}

	
	public function getOnline(){
		return $this->online;
	}

	public function setOnline($online){
		$this->online = $online;
	}

	
	public function getPoints(){
		return $this->points;
	}

	public function setPoints($points){
		$this->points = $points;
	}

	
	public function getGender(){
		return $this->gender;
	}

	public function setGender($gender){
		$this->gender = $gender;
	}

	
	public function getAdvertisement(){
		return $this->advertisement;
	}

	public function setAdvertisement($advertisement){
		$this->advertisement = $advertisement;
	}

	
	public function getValuesMetric(){
		return $this->valuesMetric;
	}

	public function setValuesMetric($valuesMetric){
		$this->valuesMetric = $valuesMetric;
	}

	
	public function getPriceCompare(){
		return $this->priceCompare;
	}

	public function setPriceCompare($priceCompare){
		$this->priceCompare = $priceCompare;
	}

	
	public function getLookingForPartner(){
		return $this->lookingForPartner;
	}

	public function setLookingForPartner($lookingForPartner){
		$this->lookingForPartner = $lookingForPartner;
	}

	
	public function getWeight(){
		return $this->weight;
	}

	public function setWeight($weight){
		$this->weight = $weight;
	}

	
	public function getHeight(){
		return $this->height;
	}

	public function setHeight($height){
		$this->height = $height;
	}

	
	public function getLastLogin(){
		return $this->lastLogin;
	}

	public function setLastLogin($lastLogin){
		$this->lastLogin = $lastLogin;
	}

	
	public function getEmail(){
		return $this->email;
	}

	public function setEmail($email){
		$this->email = $email;
	}

	
	public function getNewEmail(){
		return $this->newEmail;
	}

	public function setNewEmail($newEmail){
		$this->newEmail = $newEmail;
	}

	
	public function getPassword(){
		return $this->password;
	}

	public function setPassword($password){
		$this->password = $password;
	}

	
	public function getHash(){
		return $this->hash;
	}

	public function setHash($hash){
		$this->hash = $hash;
	}

	
	public function getLocation(){
		return $this->location;
	}

	public function setLocation($location){
		$this->location = $location;
	}

	
	public function getLanguage(){
		return $this->language;
	}

	public function setLanguage($language){
		$this->language = $language;
	}

	
	public function getDescription(){
		return $this->description;
	}

	public function setDescription($description){
		$this->description = $description;
	}

	
	public function getAvatar(){
		return $this->avatar;
	}

	public function setAvatar($avatar){
		$this->avatar = $avatar;
	}
	
	public function getState(){
		return $this->state;
	}

	public function setState($var){
		$this->state = $var;
	}
	
	public function getCity(){
		return $this->city;
	}

	public function setCity($var){
		$this->city = $var;
	}
	
	public function getBirthDate($part = null){
		if(is_null($part))return $this->birthDate;
		$arr = explode('-',$this->birthDate);
		switch($part) {
			case 'year':
				return isset($arr[0])?$arr[0]:'';
				break;
			case 'month':
				return isset($arr[1])?$arr[1]:'';
				break;
			case 'day':
				return isset($arr[2])?$arr[2]:'';
				break;
		}
	}

	public function setBirthDate($var){
		$this->birthDate = $var;
	}	

	
	public function getAge() {
		list($BirthYear,$BirthMonth,$BirthDay) = explode("-", $this->getBirthDate());
        // Find the differences
        $YearDiff = date("Y") - $BirthYear;
        $MonthDiff = date("m") - $BirthMonth;
        $DayDiff = date("d") - $BirthDay;
        // If the birthday has not occured this year
        if ($DayDiff < 0 || $MonthDiff < 0)
          $YearDiff--;
        return $YearDiff;
	}
	
	public function getBirthYear($age) {
		return date("Y-m-d", mktime(0,0,0, date("m"), date("d"), (date("Y") - $age)));
	}



	/**
	* Pobiera nazwę tabeli reprezentującej obiekt w SQL
	* @return string
	*/
	public  function GetTableName(){
	return self::$tableName;
	}

	/**
	* Pobiera nazwę klucza głównego tabeli
	* @return string
	*/
	public function GetClassTablePK() {
		return self::$classTablePK;
	}

	/**
	* Pobiera tablice mapującą pola klasy na pola tabeli
	* @return array
	*/
	public  function GetFields(){
		return self::$fields;
	}

	/**
	* Pobiera nazwę klasy
	* @return string
	*/
	public  function GetClassName(){
		return self::$className;
	}

	public function getFirstAndLastName() {
		$arr = array();
		if(strlen($this->getFirstName()) > 0)
				$arr[] = $this->getFirstName();

		if(strlen($this->getLastName()) > 0)
				$arr[] = $this->getLastName();

		return implode(' ',$arr);
	}

	public function getIsExpert() {
		return $this->isExpert();
	}

	public function setIsExpert($isExpert) {
		$this->isExpert = $isExpert;
	}

	public function isExpert() {
		return $this->isExpert?true:false;
	}

	public function setIsVip($isVip) {
		$this->isVip = $isVip;
	}

	public function getIsVip() {
		return $this->isVip;
	}

	public function isVip() {
		return $this->isVip?true:false;
	}

	public function getBadgeCache() {
		return $this->badgeCache;
	}

	public function setBadgeCache($badgeCache) {
		$this->badgeCache = $badgeCache;
	}

	public function setUserExtendedProfile($userExtendedProfile) {
		$this->userExtendedProfile = $userExtendedProfile;
	}

	public function getUserExtendedProfil() {
		return $this->userExtendedProfile;
	}

	public function getBadges() {
		if(strlen($this->badgeCache)) 
			return unserialize($this->badgeCache);
		else
			return array();
	}

	public function getUserProfilePermission() {
		return $this->userProfilePermission;
	}

	public function setUserProfilePermission($upp) {
		$this->userProfilePermission = $upp;
	}

}

?>